import Vue from 'vue'
import App from './App.vue'
import router from './router';
import axios from 'axios';
import VueAxios from 'vue-axios';
import VueLazyLoad from 'vue-lazyload';
import VueCookie from 'vue-cookie'; 
import store from './store';
import {Message} from 'element-ui';
// import env from './env';

const mock=false;
if(mock){
  require('./mock/api')
}
//设置基础的url地址
axios.defaults.baseURL='/api';//baseURL` 将自动加在 `url` 前面，除非 `url` 是一个绝对 URL
axios.defaults.timeout=8000;
//根据环境遍历配置
// axios.defaults.baseURL=env.baseURL;//baseURL` 将自动加在 `url` 前面，除非 `url` 是一个绝对 URL

//配置相应数据拦截
axios.interceptors.response.use(function(response){
  let res = response.data;
  if(res.status == 0){
    return res.data;
  }else if(res.status == 10){
    window.location.href = '/#/login';
    return Promise.reject(res);
  }else{
    Message.warning(res.msg);
    return Promise.reject(res);
  }
},(error)=>{
  let res = error.response;
  Message.error(res.data.message);
  return Promise.reject(error);
});
Vue.use(VueAxios,axios);
Vue.use(VueLazyLoad,{
  loading:'/imgs/loading-svg/loading-bars.svg'
});
Vue.use(VueCookie);
Vue.config.productionTip = false;
Vue.prototype.$message=Message;
new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app');
